<?php
/** UTF-8
 * Concentré Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Concentre
 * @package    Concentre_Archive
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version	   $ID$ r$Rev: 16 $ $Author: alban.lopez $ $Date: 2009-03-28 12:42:00 +0000 (Sat, 28 Mar 2009) $
 * @author	   S�bastien Cramattte <scramatte@zensoluciones.com>
 * @author	   Alban Lopez <alban.lopez+archive@gmail.com>
 * @see		   Based on EasyArchive <http://www.phpclasses.org/browse/package/4239.html>
 */


/**
 * @see Concentre_Archive_Interface
 */
require_once 'Concentre/Archive/Interface.php';

/**
 * @category   Concentre
 * @package    Concentre_Archive
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Concentre_Archive_Abstract
{

    /**
     * Convert an array to a stdClass object
     * 
     * @param  array $array
     * @return stdClass
     */
    protected function _toObject(Array $array)
	{
    	$return = new stdClass;

    	foreach($array as $key => $value) {
        	$return->{$key} = (is_array($value)?toObject($value):$value);
    	}

    	return $return;
	} 


    /**
     * Is tar archive
     *   
     * @param  string $src
     * @return boolean
     */	
	public function isTar($str)
	{
		$block = substr($str,0, 512);
		
		if (strlen($block)!=512) {
			return false;
		}
		
		$realchecksum = octdec(substr($str,148,8));
		$checksum = 0;
		$block = substr_replace($block, '        ', 148, 8);
		
		for ($i = 0; $i < 512; $i++) {
			$checksum += ord(substr($block, $i, 1));
		}
		
		return $realchecksum===$checksum;
		
	}	
}
